﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RPTAdmixturePowder

        public List<tb_RPT_AdmixturePowder> GetAllAdmixturePowder()
        {

            var query = (from obj in this.tb_RPT_AdmixturePowders
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }
        public List<tb_RPT_AdmixturePowder> GetAdmixturePowderBySequence(string strSequence)
        {

            var query = (from obj in this.tb_RPT_AdmixturePowders
                         where obj.IsDelete == 0 && obj.Sequence == strSequence
                         select obj).ToList();
            return query;
        }

        public List<tb_RPT_AdmixturePowder> GetAdmixturePowderByFeedWeight(string strFeedWeight)
        {

            var query = (from obj in this.tb_RPT_AdmixturePowders
                         where obj.IsDelete == 0 && obj.FeedWeight == strFeedWeight
                         select obj).ToList();
            return query;
        }


        public List<tb_RPT_AdmixturePowder> GetAdmixturePowderByFeedDate(DateTime feedDate1, DateTime feedDate2)
        {
            var query = (from obj in this.tb_RPT_AdmixturePowders
                         where obj.IsDelete == 0 &&  obj.FeedDate  >= feedDate1 &&  obj.FeedDate  <= feedDate2
                         select obj).ToList();
            return query;
        }


        public tb_RPT_AdmixturePowder GetAdmixturePowderById(int id)
        {
            return this.tb_RPT_AdmixturePowders.SingleOrDefault(tb_RPT_AdmixturePowders => tb_RPT_AdmixturePowders.Id == id);
        }

        public void CreateAdmixturePowder(tb_RPT_AdmixturePowder entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_AdmixturePowders.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyAdmixturePowder(tb_RPT_AdmixturePowder entity)
        {
            tb_RPT_AdmixturePowder instance = this.tb_RPT_AdmixturePowders.SingleOrDefault(p => p.Id == entity.Id);
            instance.Sequence = entity.Sequence;
            instance.FeedDate = entity.FeedDate;
            instance.FeedWeight = entity.FeedWeight;            
            instance.Remark = entity.Remark;

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }

        public void DeleteAdmixturePowder(tb_RPT_AdmixturePowder entity)
        {
            tb_RPT_AdmixturePowder deleteEntity = tb_RPT_AdmixturePowders.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_AdmixturePowders.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
